﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapGZKON(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveGZKON(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGZKON(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapGZKON(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertGZKON(dwLocal);
            }
            UpdateGZKON(dwLocal);
        }
        public void InsertGZKON(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO GZKON(GZKMANDANT, GZKART, GZKVAR, GZKFARBE, GZKPOS, GZKGART, GZKGVAR, GZKGFARBE, GZKZUAB, GZKANTEIL, GZKABF, GZKDISPOKZ, GZKFDZANZ, GZKEINZW1, GZKEINZW2, GZKEINZW3, GZKEINZW4, GZKTOUREN1, GZKDREHUNG1, GZKTOUREN2, GZKDREHUNG2, GZKTOUREN3, GZKDREHUNG3, GZKTOUREN4, GZKDREHUNG4, GZKFILLER)"
                + " VALUES (:GZKMANDANT, :GZKART,:GZKVAR,:GZKFARBE, :GZKPOS, :GZKART, :GZKVAR, :GZKFARBE, 0, 0, 0, 'B', 1, 0, 0, 0, 0, 0, ' ', 0, ' ', 0, ' ', 0, ' ', '                                                                   ')";
            or1.Parameters.Add("GZKMANDANT", OracleType.NVarChar).Value = dwData["GZKMANDANT"].ToString();
            or1.Parameters.Add("GZKART", OracleType.NVarChar).Value = dwData["GZKART"].ToString();
            or1.Parameters.Add("GZKVAR", OracleType.NVarChar).Value = dwData["GZKVAR"].ToString();
            or1.Parameters.Add("GZKFARBE", OracleType.NVarChar).Value = dwData["GZKFARBE"].ToString();
            or1.Parameters.Add("GZKPOS", OracleType.NVarChar).Value = dwData["GZKPOS"].ToString();
            setResult = Connect2Proxy(or1);
        }
        public DataSet QueryGZKON(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GZKON WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM GZKON WHERE  "
                            + "  GZKMANDANT=:GZKMANDANT AND GZKART=:GZKART AND GZKVAR=:GZKVAR AND GZKFARBE=:GZKFARBE AND GZKPOS=:GZKPOS";
                    or1.Parameters.Add("GZKMANDANT", OracleType.NVarChar).Value = dwData["GZKMANDANT"].ToString();
                    or1.Parameters.Add("GZKART", OracleType.NVarChar).Value = dwData["GZKART"].ToString();
                    or1.Parameters.Add("GZKVAR", OracleType.NVarChar).Value = dwData["GZKVAR"].ToString();
                    or1.Parameters.Add("GZKFARBE", OracleType.NVarChar).Value = dwData["GZKFARBE"].ToString();
                    or1.Parameters.Add("GZKPOS", OracleType.NVarChar).Value = dwData["GZKPOS"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GASTGA";
            }

            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateGZKON(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE GZKON SET "
                + "GZKMANDANT=:GZKMANDANT,"
                + "GZKART=:GZKART,"
                + "GZKVAR=:GZKVAR,"
                + "GZKFARBE=:GZKFARBE,"
                + "GZKPOS=:GZKPOS,"
                + "GZKGART=:GZKGART,"
                + "GZKGVAR=:GZKGVAR,"
                + "GZKGFARBE=:GZKGFARBE,"
                + "GZKZUAB=:GZKZUAB,"
                + "GZKANTEIL=:GZKANTEIL,"
                + "GZKABF=:GZKABF,"
                + "GZKDISPOKZ=:GZKDISPOKZ,"
                + "GZKFDZANZ=:GZKFDZANZ,"
                + "GZKEINZW1=:GZKEINZW1,"
                + "GZKEINZW2=:GZKEINZW2,"
                + "GZKEINZW3=:GZKEINZW3,"
                + "GZKEINZW4=:GZKEINZW4,"
                + "GZKTOUREN1=:GZKTOUREN1,"
                + "GZKDREHUNG1=:GZKDREHUNG1,"
                + "GZKTOUREN2=:GZKTOUREN2,"
                + "GZKDREHUNG2=:GZKDREHUNG2,"
                + "GZKTOUREN3=:GZKTOUREN3,"
                + "GZKDREHUNG3=:GZKDREHUNG3,"
                + "GZKTOUREN4=:GZKTOUREN4,"
                + "GZKDREHUNG4=:GZKDREHUNG4,"
                + "GZKFILLER=:GZKFILLER "
                + " WHERE  "
                + "  GZKMANDANT=:GZKMANDANT AND GZKART=:GZKART AND GZKVAR=:GZKVAR AND GZKFARBE=:GZKFARBE AND GZKPOS=:GZKPOS";
            or1.Parameters.Add("GZKMANDANT", OracleType.NVarChar).Value = dwData["GZKMANDANT"].ToString();
            or1.Parameters.Add("GZKART", OracleType.NVarChar).Value = dwData["GZKART"].ToString();
            or1.Parameters.Add("GZKVAR", OracleType.NVarChar).Value = dwData["GZKVAR"].ToString();
            or1.Parameters.Add("GZKFARBE", OracleType.NVarChar).Value = dwData["GZKFARBE"].ToString();
            or1.Parameters.Add("GZKPOS", OracleType.NVarChar).Value = dwData["GZKPOS"].ToString();
            or1.Parameters.Add("GZKGART", OracleType.NVarChar).Value = dwData["GZKGART"].ToString();
            or1.Parameters.Add("GZKGVAR", OracleType.NVarChar).Value = dwData["GZKGVAR"].ToString();
            or1.Parameters.Add("GZKGFARBE", OracleType.NVarChar).Value = dwData["GZKGFARBE"].ToString();
            or1.Parameters.Add("GZKZUAB", OracleType.NVarChar).Value = dwData["GZKZUAB"].ToString();
            or1.Parameters.Add("GZKANTEIL", OracleType.NVarChar).Value = dwData["GZKANTEIL"].ToString();
            or1.Parameters.Add("GZKABF", OracleType.NVarChar).Value = dwData["GZKABF"].ToString();
            or1.Parameters.Add("GZKDISPOKZ", OracleType.NVarChar).Value = dwData["GZKDISPOKZ"].ToString();
            or1.Parameters.Add("GZKFDZANZ", OracleType.NVarChar).Value = dwData["GZKFDZANZ"].ToString();
            or1.Parameters.Add("GZKEINZW1", OracleType.NVarChar).Value = dwData["GZKEINZW1"].ToString();
            or1.Parameters.Add("GZKEINZW2", OracleType.NVarChar).Value = dwData["GZKEINZW2"].ToString();
            or1.Parameters.Add("GZKEINZW3", OracleType.NVarChar).Value = dwData["GZKEINZW3"].ToString();
            or1.Parameters.Add("GZKEINZW4", OracleType.NVarChar).Value = dwData["GZKEINZW4"].ToString();
            or1.Parameters.Add("GZKTOUREN1", OracleType.NVarChar).Value = dwData["GZKTOUREN1"].ToString();
            or1.Parameters.Add("GZKDREHUNG1", OracleType.NVarChar).Value = dwData["GZKDREHUNG1"].ToString();
            or1.Parameters.Add("GZKTOUREN2", OracleType.NVarChar).Value = dwData["GZKTOUREN2"].ToString();
            or1.Parameters.Add("GZKDREHUNG2", OracleType.NVarChar).Value = dwData["GZKDREHUNG2"].ToString();
            or1.Parameters.Add("GZKTOUREN3", OracleType.NVarChar).Value = dwData["GZKTOUREN3"].ToString();
            or1.Parameters.Add("GZKDREHUNG3", OracleType.NVarChar).Value = dwData["GZKDREHUNG3"].ToString();
            or1.Parameters.Add("GZKTOUREN4", OracleType.NVarChar).Value = dwData["GZKTOUREN4"].ToString();
            or1.Parameters.Add("GZKDREHUNG4", OracleType.NVarChar).Value = dwData["GZKDREHUNG4"].ToString();
            or1.Parameters.Add("GZKFILLER", OracleType.NVarChar).Value = dwData["GZKFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
